<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="java,webservice,axis," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="在上一篇WebService实例中，基于jdk1.6以上的javax.jws 发布webservice接口。这篇博文则主要用eclipse/myeclipse 使用axis插件进行发布和调用WebService。 1. 下载axis，并解压到tomcat/webapps目录下官网地址:http://axis.apache.org/axis2/java/core/download.cgi下载 ax">
<meta name="keywords" content="java,webservice,axis">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 使用Axis实现WebService实例">
<meta property="og:url" content="http://yoursite.com/2017/09/16/pancm39/index.html">
<meta property="og:site_name" content="虚无境的博客">
<meta property="og:description" content="在上一篇WebService实例中，基于jdk1.6以上的javax.jws 发布webservice接口。这篇博文则主要用eclipse/myeclipse 使用axis插件进行发布和调用WebService。 1. 下载axis，并解压到tomcat/webapps目录下官网地址:http://axis.apache.org/axis2/java/core/download.cgi下载 ax">
<meta property="og:image" content="http://img.blog.csdn.net/20170916150831291?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916150852607?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916150914565?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916150958075?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916150946642?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151126269?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151135784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151227900?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151235024?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151242781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151251949?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151304138?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151316493?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:image" content="http://img.blog.csdn.net/20170916151334460?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:updated_time" content="2017-12-16T10:53:48.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java 使用Axis实现WebService实例">
<meta name="twitter:description" content="在上一篇WebService实例中，基于jdk1.6以上的javax.jws 发布webservice接口。这篇博文则主要用eclipse/myeclipse 使用axis插件进行发布和调用WebService。 1. 下载axis，并解压到tomcat/webapps目录下官网地址:http://axis.apache.org/axis2/java/core/download.cgi下载 ax">
<meta name="twitter:image" content="http://img.blog.csdn.net/20170916150831291?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/09/16/pancm39/"/>






  <title>Java 使用Axis实现WebService实例 | 虚无境的博客</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?39c177d10f6e05ddfa113e02139b9c1c";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">虚无境的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/09/16/pancm39/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="虚无境">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/xuwujing.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="虚无境的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java 使用Axis实现WebService实例</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-16T15:26:33+08:00">
                2017-09-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/webservice/" itemprop="url" rel="index">
                    <span itemprop="name">webservice</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <script src="\assets\js\APlayer.min.js"> </script><p>在<a href="http://blog.csdn.net/qazwsxpcm/article/details/70370490" target="_blank" rel="external">上一篇WebService实例</a>中，基于jdk1.6以上的javax.jws 发布webservice接口。这篇博文则主要用eclipse/myeclipse 使用axis插件进行发布和调用WebService。</p>
<h3 id="1-下载axis，并解压到tomcat-webapps目录下"><a href="#1-下载axis，并解压到tomcat-webapps目录下" class="headerlink" title="1. 下载axis，并解压到tomcat/webapps目录下"></a>1. 下载axis，并解压到tomcat/webapps目录下</h3><p>官网地址:<a href="http://axis.apache.org/axis2/java/core/download.cgi" target="_blank" rel="external">http://axis.apache.org/axis2/java/core/download.cgi</a><br>下载 axis2-xx-war.zip，并解压到tomcat/webapps</p>
<p><img src="http://img.blog.csdn.net/20170916150831291?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"><br><img src="http://img.blog.csdn.net/20170916150852607?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<h3 id="2-在tomcat部署axis2"><a href="#2-在tomcat部署axis2" class="headerlink" title="2. 在tomcat部署axis2"></a>2. 在tomcat部署axis2</h3><p>启动tomcat, 可以看到多了个axis2文件<br>在浏览器输入:<a href="http://localhost:8080/axis2/" target="_blank" rel="external">http://localhost:8080/axis2/</a><br>看到axis界面，则成功发布<br><img src="http://img.blog.csdn.net/20170916150914565?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916150958075?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<h3 id="3-在eclipse-myeclipse-安装axis插件"><a href="#3-在eclipse-myeclipse-安装axis插件" class="headerlink" title="3. 在eclipse/myeclipse 安装axis插件"></a>3. 在eclipse/myeclipse 安装axis插件</h3><p>将下载下来的axis2-eclipse-codegen-plugin-x.x.x.zip和axis2-eclipse-service-plugin-x.x.x.zip 解压，解压之后的jar文件复制到eclipse/myeclipse 的dropins目录下，重启eclipse/myeclipse，右键File-&gt;New-&gt;Other 可以看到axis插件已经安装成功。<br><img src="http://img.blog.csdn.net/20170916150946642?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151126269?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151135784?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<h3 id="4-发布WebService"><a href="#4-发布WebService" class="headerlink" title="4. 发布WebService"></a>4. 发布WebService</h3><p>将下载下来的axis2-x.x.x-bin 解压，将其中的lib架包添加置项目中。<br>新建class类，用于发布。<br>编译该类之后，用axis2发布该类。<br>右键New -&gt; File -&gt; Other -&gt; Axis2 wizards -&gt; Axis2 Services Archiver 。<br>选择该class类生成的路径，注意只到classes目录下， 然后next，勾上Skip WSDL，点击next，点击next，service填写发布的名称, class name填写路径，包名加上类名，然后选择发布的方法。继续next，选择tomcat/webapps目录下的axis/web-inf/service。<br>发布成功后，启动tomcat，在浏览器输入:<a href="http://localhost:8080/axis2/services/listServices" target="_blank" rel="external">http://localhost:8080/axis2/services/listServices</a> 。可以看到要发布的webservice ，点击该项目，进入wsdl界面。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * </div><div class="line">* Title: AxisServiceHello</div><div class="line">* Description: Axis2 发布</div><div class="line">* Version:1.0.0  </div><div class="line">* @author panchengming</div><div class="line"> */</div><div class="line">public class AxisServiceHello &#123;</div><div class="line">	</div><div class="line">	/** 供客户端调用方法  </div><div class="line">	 * @param name  传入参数</div><div class="line">	 * @return String 返回结果</div><div class="line">	 * */</div><div class="line">	public String getValue(String name)&#123;</div><div class="line">		return &quot;Axis 欢迎你！ &quot;+name;</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><img src="http://img.blog.csdn.net/20170916151227900?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151235024?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151242781?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151251949?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151304138?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p><img src="http://img.blog.csdn.net/20170916151316493?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<h3 id="5-调用WebService"><a href="#5-调用WebService" class="headerlink" title="5. 调用WebService"></a>5. 调用WebService</h3><p>新建一个class类，用于调用发布的webservice。<br>可以使用rpc或document两种方法调用，运行main方法，看到打印消息，调用成功。<br>注:调用需要将tomcat服务启动，在浏览器输入wsdl地址能够查看。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div></pre></td><td class="code"><pre><div class="line">import java.io.IOException;</div><div class="line"></div><div class="line">import javax.xml.namespace.QName;</div><div class="line"></div><div class="line">import org.apache.axiom.om.OMAbstractFactory;</div><div class="line">import org.apache.axiom.om.OMElement;</div><div class="line">import org.apache.axiom.om.OMFactory;</div><div class="line">import org.apache.axiom.om.OMNamespace;</div><div class="line">import org.apache.axis2.AxisFault;</div><div class="line">import org.apache.axis2.addressing.EndpointReference;</div><div class="line">import org.apache.axis2.client.Options;</div><div class="line">import org.apache.axis2.client.ServiceClient;</div><div class="line">import org.apache.axis2.rpc.client.RPCServiceClient;</div><div class="line"></div><div class="line"></div><div class="line">/**</div><div class="line"> * </div><div class="line">* Title: AxisClientHello</div><div class="line">* Description: webService 客户端调用</div><div class="line">* Version:1.0.0  </div><div class="line">* @author panchengming</div><div class="line"> */</div><div class="line">public class AxisClientHello &#123;</div><div class="line">	private final static String url=&quot;http://192.168.1.105:8080/axis2/services/AxisServiceHello?wsdl&quot;; //wsdl地址 </div><div class="line">	private final static String data=&quot;PanChengMing&quot;;												   //参数</div><div class="line">	private final static String tns = &quot;http://service.pcm.com&quot;;  									   //命名空间</div><div class="line">	private final static String method=&quot;getValue&quot;;												  //调用的方法</div><div class="line">	</div><div class="line">	 //调用webservice</div><div class="line">	public static void main(String[] args) throws  IOException&#123;</div><div class="line">			getRPC();			//调用方法一</div><div class="line">			getDocument();		//调用方法二</div><div class="line">	&#125;</div><div class="line">	</div><div class="line">	</div><div class="line">	</div><div class="line">    /**  </div><div class="line">     * 方法一：  </div><div class="line">     * 应用rpc的方式调用 这种方式就等于远程调用，  </div><div class="line">     * 即通过url定位告诉远程服务器，告知方法名称，参数等， 调用远程服务，得到结果。  </div><div class="line">     * 使用 org.apache.axis2.rpc.client.RPCServiceClient类调用WebService  </div><div class="line">     *  </div><div class="line">        【注】：  </div><div class="line">          </div><div class="line">            如果被调用的WebService方法有返回值 应使用 invokeBlocking 方法 该方法有三个参数  </div><div class="line">              第一个参数的类型是QName对象，表示要调用的方法名；  </div><div class="line">              第二个参数表示要调用的WebService方法的参数值，参数类型为Object[]；  </div><div class="line">                当方法没有参数时，invokeBlocking方法的第二个参数值不能是null，而要使用new Object[]&#123;&#125;。  </div><div class="line">              第三个参数表示WebService方法的 返回值类型的Class对象，参数类型为Class[]。  </div><div class="line">            如果被调用的WebService方法没有返回值 应使用 invokeRobust 方法  </div><div class="line">              该方法只有两个参数，它们的含义与invokeBlocking方法的前两个参数的含义相同。  </div><div class="line">      </div><div class="line">            在创建QName对象时，QName类的构造方法的第一个参数表示WSDL文件的命名空间名，  </div><div class="line">            也就是 &lt;wsdl:definitions&gt;元素的targetNamespace属性值。  </div><div class="line">     *  </div><div class="line">     */  </div><div class="line">     @SuppressWarnings(&quot;rawtypes&quot;)</div><div class="line">	public static void getRPC() throws AxisFault&#123; </div><div class="line">        RPCServiceClient serviceClient = new RPCServiceClient();</div><div class="line">        Options options = serviceClient.getOptions();</div><div class="line">        // 指定调用WebService的URL</div><div class="line">        EndpointReference targetEPR = new EndpointReference(url);</div><div class="line">        options.setTo(targetEPR);</div><div class="line"></div><div class="line">        // 指定要调用的WSDL文件的命名空间及getValue方法</div><div class="line">        QName qn = new QName(tns, method);</div><div class="line">        // 指定getValue方法的参数值</div><div class="line">        Object[] ob = new Object[] &#123; data &#125;;</div><div class="line">        // 指定getValue方法返回值的数据类型的Class对象</div><div class="line">        Class[] classes = new Class[] &#123; String.class &#125;;</div><div class="line">        // 调用getValue方法并输出该方法的返回值</div><div class="line">        System.out.println(serviceClient.invokeBlocking(qn, ob, classes)[0]);</div><div class="line">	&#125;</div><div class="line">     </div><div class="line">     /**  </div><div class="line">      * 方法二： 应用document方式调用  </div><div class="line">      * 用ducument方式应用现对繁琐而灵活。现在用的比较多。因为真正摆脱了我们不想要的耦合  </div><div class="line">      */  </div><div class="line">     public static void getDocument() throws AxisFault&#123; </div><div class="line">    	  OMElement result = null;  </div><div class="line">          try &#123;  </div><div class="line">              Options options = new Options();  </div><div class="line">              // 指定调用WebService的URL    </div><div class="line">              EndpointReference targetEPR = new EndpointReference(url);  </div><div class="line">              options.setTo(targetEPR);         </div><div class="line">              ServiceClient sender = new ServiceClient();  </div><div class="line">              sender.setOptions(options);  </div><div class="line">    </div><div class="line">              OMFactory fac = OMAbstractFactory.getOMFactory();  </div><div class="line">              // 命名空间</div><div class="line">              OMNamespace omNs = fac.createOMNamespace(tns, &quot;&quot;);  </div><div class="line">              </div><div class="line">              OMElement ot = fac.createOMElement(method, omNs);  </div><div class="line">              OMElement symbol = fac.createOMElement(&quot;name&quot;, omNs);  </div><div class="line">              symbol.addChild(fac.createOMText(symbol, data));  </div><div class="line">              ot.addChild(symbol);  </div><div class="line">              result=sender.sendReceive(ot);</div><div class="line">              System.out.println(result);  </div><div class="line">          &#125; catch (AxisFault axisFault) &#123;  </div><div class="line">              axisFault.printStackTrace();  </div><div class="line">          &#125;  </div><div class="line">     &#125;</div><div class="line">	</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p><img src="http://img.blog.csdn.net/20170916151334460?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWF6d3N4cGNt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描述"></p>
<p>结语:使用axis实现webservice 暂时告一段落了，这次的demo和上篇的<a href="http://blog.csdn.net/qazwsxpcm/article/details/70370490" target="_blank" rel="external">webservice</a>的demo 我整合成了一个项目，发布到我的github上了 ,<a href="https://github.com/xuwujing/webservice_project" target="_blank" rel="external">https://github.com/xuwujing/webservice_project</a> 。 有兴趣的可以看看。</p>
<p>版权声明:<br>作者：虚无境<br>博客园出处：<a href="http://www.cnblogs.com/xuwujing" target="_blank" rel="external">http://www.cnblogs.com/xuwujing</a><br>CSDN出处：<a href="http://blog.csdn.net/qazwsxpcm" target="_blank" rel="external">http://blog.csdn.net/qazwsxpcm</a>　　　　<br>个人博客出处：<a href="http://www.panchengming.com" target="_blank" rel="external">http://www.panchengming.com</a><br>原创不易，转载请标明出处，谢谢！</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>
     
    <div>
	 +
	  
<div style="text-align:center;color: #ccc;font-size:14px;">
------ 本文结束 ------</div>
<br/>
<div style="border: 1px solid black">
<div style="margin-left:10px">
<span style="font-weight:blod">版权声明</span>
<!-- <img src="/images/xuwujing.png" > -->
<br/>
<p style="font-size: 10px;line-height: 30px"><a href="http://www.panchengming.com/" style="color:#258FC6">xuwujing's Notes</a> by <a href="http://www.panchengming.com/" style="color:#258FC6">ChengMing Pan</a> is licensed under a <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" style="color:#258FC6">Creative Commons BY-NC-ND 4.0 International License</a>.<br/>
由<a href="http://www.panchengming.com/" style="color:#258FC6">虚无境</a>创作并维护的<a href="http://www.panchengming.com/" style="color:#258FC6">xuwujing's Notes</a>博客采用<a href="https://creativecommons.org/licenses/by-nc-nd/4.0/" style="color:#258FC6">创作共用保留署名-非商业-禁止演绎4.0国际许可证</a>。<br/>
本文首发于<a href="http://www.panchengming.com/" style="color:#258FC6">xuwujing's Notes</a> 博客（ <a href="http://www.panchengming.com/" style="color:#258FC6">http://www.panchengming.com/</a> ），版权所有，侵权必究。</p>
</div>
</div>

	
	</div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag"># java</a>
          
            <a href="/tags/webservice/" rel="tag"># webservice</a>
          
            <a href="/tags/axis/" rel="tag"># axis</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/09/pancm51/" rel="next" title="tomcat管理界面登录无法进入">
                <i class="fa fa-chevron-left"></i> tomcat管理界面登录无法进入
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/23/pancm53/" rel="prev" title="MyEclipse  新手使用教程---图文详解">
                MyEclipse  新手使用教程---图文详解 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/xuwujing.png"
               alt="虚无境" />
          <p class="site-author-name" itemprop="name">虚无境</p>
           
              <p class="site-description motion-element" itemprop="description">The way of the future!</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">136</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">30</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">59</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/xuwujing" target="_blank" title="github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  github
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://blog.csdn.net/qazwsxpcm?viewmode=list" target="_blank" title="csdn">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  csdn
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://home.cnblogs.com/u/xuwujing/" target="_blank" title="cnblogs">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  cnblogs
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.woainia.site/" title="woainia" target="_blank">woainia</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://cmsblogs.com/" title="chenssy" target="_blank">chenssy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://italker.imisty.cn" title="xiaowu" target="_blank">xiaowu</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-下载axis，并解压到tomcat-webapps目录下"><span class="nav-number">1.</span> <span class="nav-text">1. 下载axis，并解压到tomcat/webapps目录下</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-在tomcat部署axis2"><span class="nav-number">2.</span> <span class="nav-text">2. 在tomcat部署axis2</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-在eclipse-myeclipse-安装axis插件"><span class="nav-number">3.</span> <span class="nav-text">3. 在eclipse/myeclipse 安装axis插件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-发布WebService"><span class="nav-number">4.</span> <span class="nav-text">4. 发布WebService</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-调用WebService"><span class="nav-number">5.</span> <span class="nav-text">5. 调用WebService</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">虚无境</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
 | 
本站总访问量<span id="busuanzi_value_site_pv"></span>次
 | 
本站访客数<span id="busuanzi_value_site_uv"></span>人次
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=857896&auto=0&height=66"></iframe>



        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
